home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacTech 1 to 12
/
MacTech-vol-1-12.toast
/
Tools
/
Alpha 6.51b13 ƒ
/
Tcl
/
UserCode
/
smartSource.tcl
< prev
next >
Wrap
Text File
|
1996-08-15
|
3KB
|
77 lines
#==============================================================================
# smart-source.tcl
#
# Copyright 1994, Robert Browning (osiris@cs.utexas.edu): This code is made
# freely available to anyone who can find a use for it. Consider it part of my
# thanks to all those who have contributed to the freeware and shareware base.
# (Especially Peter Keheler, without which this code would be pretty useless).
#
#==============================================================================
#
# This file implements a replacement source command. It is intended to help
# make the process of augmenting Alpha's code base with your own changes less
# awkward, especially in the face of program updates. It also makes it so
# that you no longer have to source files containing procedures that you want
# to override in your UserStartup file.
#
# Basically, you designate a directory (right now it has to be a directory
# named TclExtensions in the $HOME directory) to contain your files. Then
# anytime Alpha is instructed to source a file named filename.tcl, it will
# first look in the directory you have designated, and if there is a file of
# the identical name there (i.e. filename.tcl) it will source that file
# instead of the original one specified. If there are any files named
# filename**.tcl it will source those in the order returned by glob after
# either the original filename.tcl or the replacement has been sourced.
#
# For example, if your TclExtensions directory contains files named
# latex*1.tcl and latex*2.tcl, then whenever you try to open a latex file
# Alpha will first source the standard latex.tcl file, then latex*1.tcl, then
# latex*2.tcl. If there was also a file named latex.tcl in the TclExtensions
# directory then that file would be sourced in place of the standard
# latex.tcl, then latex*1.tcl, then latex*2.tcl.
#
# You may just want to use filename*.tcl for a single extension file.
#
#==============================================================================
#
# To Do:
#
# Add the ability to dynamically locate the TclExtensions directory.
#
# (Feel free to make suggestions or improve this code.)
#
#==============================================================================
set tclExtensionsDir "$HOME:TclExtensions"
if {[file exists "$tclExtensionsDir"]} {
if {![string length [info commands oldSource]]} {
rename source oldSource
}
proc source {filename} {
global tclExtensionsDir
set justName [file tail "$filename"]
set overrideFile "${tclExtensionsDir}:${justName}"
if {[file exists $overrideFile]} {
set returnVal [uplevel 1 oldSource "$overrideFile"]
} else {
set returnVal [uplevel 1 oldSource "$filename"]
}
set baseName [string range ${justName} 0 \
[expr [string length ${justName}] - \
[string length [file extension ${justName}]] - 1]]
set extensionFiles \
[glob -nocomplain "${tclExtensionsDir}:${baseName}**.tcl"]
foreach extensionFile $extensionFiles {
set returnVal [uplevel 1 oldSource "$extensionFile"]
}
return "$returnVal"
}
}